Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 6 - Expressions / Operations
Operators That Handle Operands of Various Classes


Concatenation

The concatenation operator (&) can handle operands of any class.

STRING
The concatenation of two strings is a string that begins with the characters in the string to the left of the operator, followed immediately by the characters
in the string to the right of the operator. AppleScript does not add spaces or other characters between the two strings. For example,

"dump" & "truck"
returns the string "dumptruck".

If the operand to the left of the operator is a string, but the operand to the right is not, AppleScript attempts to coerce the operand to the right to a string. For example, when AppleScript evaluates the expression

"Route " & 66
it coerces the integer 66 to the string "66", and the result is

"Route 66"
RECORD
The concatenation of two records is a record that begins with the properties
of the record to the left of the operator, followed by the properties of the record to the right of the operator. If both records contain properties with the same name, the value of the property from the record to the left of the operator appears in the result. For example, the result of the expression

{ name:"Eric", mileage:"8000" } & ÿ   { name:"Mitch", framesize:58 }
is

{ name:"Eric", mileage:"8000", frameSize:58 }
ALL OTHER CLASSES
The concatenation of two operands that are not strings or records is a list whose first item is the value of the operand to the left of the operator, and whose second item is the value of the operand to the right of the operator.
If the operands to be concatenated are lists, then the result is a list containing all the items in the list to the left of the operator, followed by all the items in
the list to the right of the operator. For example,

{ "This" } & { "and", "that" }
returns a list containing three items:

{ "This", "and", "that" }

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996